def generateParenthesis(n, res, left, right, str):
    if left < right:
        return
    if left == right == n:
        res.append(str)
    if left < n:
        generateParenthesis(n, res, left + 1, right, str + '(')
    if right < n:
        generateParenthesis(n, res, left, right + 1, str + ')')
    return res


res = []
generateParenthesis(2, res, 0, 0, '')
print(res)
